﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Business_Objects;
using ServicesComponent.Repositories;
using log4net;
using System.Web.Security;
using System.Web.Configuration;

public partial class Login : System.Web.UI.Page
{
    private static readonly ILog _logger = LogManager.GetLogger(typeof(Login).Name);
    private IUserRepository _UserRepository; 
    protected void Page_Load(object sender, EventArgs e)
    {
        _UserRepository = FactoryServices.GetServicesUser(_UserRepository);
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
         
    }


    protected void myLogin_LoginError(object sender, EventArgs e)
    {

    }
    public string GetConfigValue(string configname)
    {
        return WebConfigurationManager.AppSettings[configname];
    }

    protected void btnLogin_Click(object sender, EventArgs e)
    {
        User user = GetUserByUserNameAndPassword(txtUserName.Value, txtPassword.Value);
        if (user!=null)
        {
            Session["Username"] = user.UserName;
            Session["SchoolID"] = user.SchoolId;
//            Session["TruongID"] = user.TruongId;
            Response.Redirect("Default.aspx");
          
        }
        else
        {
            Alert.Show("Tên đăng nhập hoạc mật khẩu chưa chính xác!");
        }
    }
    User GetUserByUserNameAndPassword(string username, string password)
    {
      


        return _UserRepository.GetUserByUserNameAndPassword(username,password);
    }

}

